package com.canaan.business.controller.pc.basic;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.basic.Owner;
import com.canaan.business.service.basic.IOwnerService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * 货主Controller
 *
 * @author canaan
 * @date 2025-03-24
 */
@Api(tags = "货主")
@RestController
@RequestMapping("/basic/owner")
public class OwnerController extends BaseController {
    @Resource
    private IOwnerService ownerService;

    /**
     * 查询货主列表
     */
    @ApiOperation(value = "查询货主列表")
    @PreAuthorize("@ss.hasPermi('basic:owner:list')")
    @GetMapping("/list")
    public TableDataInfo list(Owner owner) {
        startPage();
        List<Owner> list = ownerService.selectOwnerList(owner);
        return getDataTable(list);
    }

    /**
     * 导出货主列表
     */
    @ApiOperation(value = "导出货主列表")
    @PreAuthorize("@ss.hasPermi('basic:owner:export')")
    @Log(title = "货主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Owner owner) {
        List<Owner> list = ownerService.selectOwnerList(owner);
        ExcelUtil<Owner> util = new ExcelUtil<Owner>(Owner.class);
        util.exportExcel(response, list, "货主数据");
    }

    /**
     * 获取货主详细信息
     */
    @ApiOperation(value = "获取货主详细信息")
    @PreAuthorize("@ss.hasPermi('basic:owner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ownerService.selectOwnerById(id));
    }

    /**
     * 新增货主
     */
    @ApiOperation(value = "新增货主")
    @PreAuthorize("@ss.hasPermi('basic:owner:add')")
    @Log(title = "货主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Owner owner) {
        return toAjax(ownerService.insertOwner(owner));
    }

    /**
     * 修改货主
     */
    @ApiOperation(value = "修改货主")
    @PreAuthorize("@ss.hasPermi('basic:owner:edit')")
    @Log(title = "货主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Owner owner) {
        return toAjax(ownerService.updateOwner(owner));
    }

    /**
     * 删除货主
     */
    @ApiOperation(value = "删除货主")
    @PreAuthorize("@ss.hasPermi('basic:owner:remove')")
    @Log(title = "货主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ownerService.deleteOwnerByIds(ids));
    }
}
